<template>
  <div class="app-container">
    <el-card class="filter-container" shadow="never">
      <div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
        <el-button style="float:right" type="primary" @click="handleSearchList()" size="small">查询搜索</el-button>
        <el-button
          style="float:right;margin-right: 15px"
          @click="handleResetSearch()"
          size="small"
        >重置</el-button>
      </div>
      <div style="margin-top: 15px">
        <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
          <el-form-item label="输入搜索：">
            <el-input
              v-model="listQuery.keyword"
              class="input-width"
              placeholder="帐户名/手机号"
              clearable
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表</span>
    </el-card>
    <div class="table-container">
      <el-table ref="adminTable" :data="list" style="width: 100%;" v-loading="listLoading" border>
        <el-table-column label="编号" width="100" align="center">
          <template slot-scope="scope">{{scope.row.id}}</template>
        </el-table-column>
        <el-table-column label="头像" width="160" align="center">
          <template slot-scope="scope">
            <el-image
              style="width: 48px; height: 48px"
              :src="scope.row.avatarUrl"
              :fit="'fill'"
              :preview-src-list="[scope.row.avatarUrl || '']"
            ></el-image>
          </template>
        </el-table-column>
        <el-table-column label="账户名" align="center">
          <template slot-scope="scope">{{scope.row.name}}</template>
        </el-table-column>
        <el-table-column label="微信名" align="center">
          <template slot-scope="scope">{{scope.row.wxName}}</template>
        </el-table-column>
        <el-table-column label="手机号" align="center">
          <template slot-scope="scope">{{scope.row.phone}}</template>
        </el-table-column>
        <el-table-column label="资质信息" width="150" align="center">
          <template slot-scope="scope">
<div v-if="scope.row.fileurl">  
   <el-button
  type="success"
  size="mini"
  @click="showfile(scope.row.fileurl)"
>查看用户资质</el-button></div>
<div v-else>用户未上传资质</div>
          </template>
        </el-table-column>
        <el-table-column label="邮箱" width="160" align="center">
          <template slot-scope="scope">{{scope.row.email}}</template>
        </el-table-column>
        <el-table-column label="地址" width="160" align="center">
          <template slot-scope="scope">{{scope.row.address}}</template>
        </el-table-column>
        <el-table-column label="用户状态" width="160" align="center">
          <template slot-scope="scope">
            <el-tag type="danger" v-if="scope.row.status === '-1'">已注销</el-tag>
            <el-tag type="info" v-if="scope.row.status === '0'">黑名单用户</el-tag>
            <el-tag type="success" v-if="scope.row.status === '1'">正常</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="300" align="center">
          <template slot-scope="scope">
            <el-button
              type="success"
              size="mini"
              v-if="scope.row.status === '0'"
              @click="changeMiniUserStatus(scope.row, '1')"
            >启用用户</el-button>
            <el-button
              type="info"
              size="mini"
              v-if="scope.row.status === '1'"
              @click="changeMiniUserStatus(scope.row, '0')"
            >加入黑名单</el-button>
            <el-button
              type="danger"
              size="mini"
              v-if="scope.row.status !== '-1'"
              @click="changeMiniUserStatus(scope.row, '-1')"
            >注销用户</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery.pageNum"
        :page-size="listQuery.pageSize"
        :page-sizes="[10,15,20]"
        :total="total"
      ></el-pagination>
    </div>
    <el-dialog
    title="资质信息"
    :visible.sync="showfiledDialog"
    width="40%"
    :before-close="handleClose">
    <div class="sucai">
      <img :src="showfileurl" alt="资质图片"/>
    </div>
   
  </el-dialog>
  </div>
</template>
<script>
import { getUserList, changeMiniUserStatus } from "@/api/auser";

const defaultListQuery = {
  pageNum: 1,
  pageSize: 10,
  keyword: null
};
export default {
  name: "adminList",
  data() {
    return {
      listQuery: Object.assign({}, defaultListQuery),
      list: null,
      total: null,
      listLoading: false,
      showfileurl:'',
      showfiledDialog:false
    };
  },
  created() {
    this.getList();
  },
  methods: {
    // 查看用户资质
    showfile(url){
this.showfiledDialog=true
this.showfileurl=url
    },
    handleClose(){
      this.showfiledDialog=false
      this.showfileurl=''
    },
    handleResetSearch() {
      this.listQuery = Object.assign({}, defaultListQuery);
    },
    handleSearchList() {
      this.listQuery.pageNum = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.pageNum = val;
      this.getList();
    },
    changeMiniUserStatus(row, status) {
      let tip = {
        "-1": { msg: "确定要注销该用户吗？", type: "danger" },
        "0": { msg: "确定要将该用户加入黑名单吗？", type: "info" },
        "1": { msg: "确定要启用该用户吗？", type: "success" }
      };

      this.$confirm(tip[status].msg, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: tip[status].type
      }).then(() => {
        changeMiniUserStatus({
          id: row.id,
          status: status
        }).then(response => {
          this.$message({
            type: "success",
            message: "操作成功"
          });
          this.getList();
        });
      });
    },
    getList() {
      this.listLoading = true;
      getUserList(this.listQuery).then(response => {
        this.listLoading = false;
        this.list = response.data.list;
        this.total = response.data.total;
      });
    },
  }
};
</script>
<style  scoped>
.sucai img,.sucai video{
width: 100%;
height: 100%;
}
</style>


